/********************************************
 * 
 * 타이틀 : 윈도우 프레임 
 * 기능 : 
 * 작성자 : LJI
 * 작성일 : 2013.09.26
 * 
 ********************************************/

package com.game.pacman.client;
import java.awt.CardLayout;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.Toolkit;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;


public class GameFrame extends JFrame{
	public static CardLayout card;    
	public static JPanel mainScreen;

	//이미지 파일
	private Image imageMenuBack;	
	private Image imageCreditBack;
	private Image imageCreditButton;	
	private Image imageRankBack;
	private Image imageRankButton;
	
	//스크린구성
	private MenuScreen menuScreen;    //메뉴화면
	private PlayScreen playScreen;    //게임화면
	private RankScreen rankScreen;        	//순위화면
	private CreditScreen creditScreen;      //크래딧화면
	
	//통신용
	private Client client;
	
	public GameFrame(){
		//comm(); //통신
		loadImage();  
		init();  //초기화
	}
	
	public void init(){	
		mainScreen = new JPanel();
		
		card = new CardLayout(0,0); //Layout 설정
		mainScreen.setLayout(card);	
		
		Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();  //해상도 가져오기
		setLocation(((int)screen.getWidth()-Constants.WINDOW_WIDTH)/2,((int)screen.getHeight()-Constants.WINDOW_HEIGHT)/2);
		setPreferredSize(new Dimension(Constants.WINDOW_WIDTH,Constants.WINDOW_HEIGHT));
		setTitle("Pacman 2014");
		setResizable(false);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				
		//플레이 화면 카드레이아웃에 등록
		playScreen = new PlayScreen();
		card.addLayoutComponent(playScreen, Constants.PLAY_SCREEN);
		mainScreen.add(Constants.PLAY_SCREEN,playScreen);
		
		//메뉴 선택 화면 카드레이아웃에 등록
		//menuScreen = new MenuScreen(imageMenuBack,client);
		menuScreen = new MenuScreen(imageMenuBack,client,playScreen);
		card.addLayoutComponent(menuScreen,Constants.MENU_SCREEN);
		mainScreen.add(Constants.MENU_SCREEN,menuScreen);

		//순위 화면 카드레이아웃에 등록
		rankScreen= new RankScreen(imageRankBack,imageRankButton);
		card.addLayoutComponent(rankScreen,Constants.RANK_SCREEN);
		mainScreen.add(Constants.RANK_SCREEN,rankScreen);
		
		//크래딧 화면 카드레이아웃에 등록
		creditScreen= new CreditScreen(imageRankBack,imageRankButton);
		card.addLayoutComponent(creditScreen,Constants.CREDIT_SCREEN);
		mainScreen.add(Constants.CREDIT_SCREEN,creditScreen);
		
		add(mainScreen);

		//메인화면으로 시작하기
		card.show(mainScreen, Constants.MENU_SCREEN);
		//card.show(mainScreen, Constants.PLAY_SCREEN);
		pack();
	}	
	
	public void loadImage(){
		//상대경로
		imageMenuBack = new ImageIcon("src/image/pacman_main.jpg").getImage();
		imageCreditBack = new ImageIcon("src/image/pacman_main.jpg").getImage();
		imageCreditButton = new ImageIcon("src/image/tomain.png").getImage();
		imageRankBack = new ImageIcon("src/image/pacman_main.jpg").getImage();
		imageRankButton = new ImageIcon("src/image/tomain.png").getImage();
		
		//절대경로
//		imageMenuBack = new ImageIcon("J:\\workspace\\Test03_Template\\pacman_main.jpg").getImage();
//		imageCreditBack = new ImageIcon("J:\\workspace\\Test03_Template\\Tulips.jpg").getImage();
//		imageCreditButton = new ImageIcon("J:\\workspace\\Test03_Template\\tomain.png").getImage();
//		imageRankBack = new ImageIcon("J:\\workspace\\Test03_Template\\Tulips.jpg").getImage();
//		imageRankButton = new ImageIcon("J:\\workspace\\Test03_Template\\tomain.png").getImage();			
	}
	
	public void comm(){
		client = new Client();
		client.startClient();  //통신시작
	}
}
